using Microsoft.Phone.Controls.Primitives;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Collections.Specialized;
using System.ComponentModel;
using System.Linq;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Controls.Primitives;
using System.Windows.Input;
using System.Windows.Media;
namespace Microsoft.Phone.Controls
{
	[TemplatePart(Name = "TemplatedListBox", Type = typeof(TemplatedListBox))]
	public class LongListSelector : Control
	{
		private class GroupSelectedEventArgs : EventArgs
		{
			public object Group
			{
				get;
				private set;
			}
			public GroupSelectedEventArgs(object group)
			{
				this.Group = group;
			}
		}
		private delegate void GroupSelectedEventHandler(object sender, LongListSelector.GroupSelectedEventArgs e);
		private class LongListSelectorItemsControl : ItemsControl
		{
			public event LongListSelector.GroupSelectedEventHandler GroupSelected;
			protected override void PrepareContainerForItemOverride(DependencyObject element, object item)
			{
				base.PrepareContainerForItemOverride(element, item);
				((UIElement)element).add_Tap(new EventHandler<GestureEventArgs>(this.LongListSelectorItemsControl_Tap));
			}
			protected override void ClearContainerForItemOverride(DependencyObject element, object item)
			{
				base.ClearContainerForItemOverride(element, item);
				((UIElement)element).remove_Tap(new EventHandler<GestureEventArgs>(this.LongListSelectorItemsControl_Tap));
			}
			private void LongListSelectorItemsControl_Tap(object sender, GestureEventArgs e)
			{
				ContentPresenter contentPresenter = sender as ContentPresenter;
				if (contentPresenter != null)
				{
					LongListSelector.GroupSelectedEventHandler groupSelected = this.GroupSelected;
					if (groupSelected != null)
					{
						LongListSelector.GroupSelectedEventArgs e2 = new LongListSelector.GroupSelectedEventArgs(contentPresenter.get_Content());
						groupSelected(this, e2);
					}
				}
			}
		}
		private const string TemplatedListBoxName = "TemplatedListBox";
		private const double BufferSizeDefault = 1.0;
		private const string ScrollingState = "Scrolling";
		private const string NotScrollingState = "NotScrolling";
		private const string CompressionTop = "CompressionTop";
		private const string CompressionBottom = "CompressionBottom";
		private const string NoVerticalCompression = "NoVerticalCompression";
		private const string VerticalCompressionStateName = "VerticalCompression";
		private const string ScrollStatesGroupName = "ScrollStates";
		private PhoneApplicationPage _page;
		private bool _systemTrayVisible;
		private bool _applicationBarVisible;
		private Border _border;
		private LongListSelector.LongListSelectorItemsControl _itemsControl;
		private Popup _groupSelectorPopup;
		private static readonly double _screenWidth = Application.get_Current().get_Host().get_Content().get_ActualWidth();
		private static readonly double _screenHeight = Application.get_Current().get_Host().get_Content().get_ActualHeight();
		private TemplatedListBox _listBox;
		private VisualStateGroup _scrollGroup;
		private VisualStateGroup _verticalCompressionGroup;
		private INotifyCollectionChanged _rootCollection;
		private List<INotifyCollectionChanged> _groupCollections = new List<INotifyCollectionChanged>();
		public static readonly DependencyProperty ItemsSourceProperty = DependencyProperty.Register("ItemsSource", typeof(IEnumerable), typeof(LongListSelector), new PropertyMetadata(null, new PropertyChangedCallback(LongListSelector.OnItemsSourceChanged)));
		public static readonly DependencyProperty ListHeaderProperty = DependencyProperty.Register("ListHeader", typeof(object), typeof(LongListSelector), new PropertyMetadata(null));
		public static readonly DependencyProperty ListHeaderTemplateProperty = DependencyProperty.Register("ListHeaderTemplate", typeof(DataTemplate), typeof(LongListSelector), new PropertyMetadata(null, new PropertyChangedCallback(LongListSelector.OnDataTemplateChanged)));
		public static readonly DependencyProperty ListFooterProperty = DependencyProperty.Register("ListFooter", typeof(object), typeof(LongListSelector), new PropertyMetadata(null));
		public static readonly DependencyProperty ListFooterTemplateProperty = DependencyProperty.Register("ListFooterTemplate", typeof(DataTemplate), typeof(LongListSelector), new PropertyMetadata(null, new PropertyChangedCallback(LongListSelector.OnDataTemplateChanged)));
		public static readonly DependencyProperty GroupHeaderProperty = DependencyProperty.Register("GroupHeaderTemplate", typeof(DataTemplate), typeof(LongListSelector), new PropertyMetadata(null, new PropertyChangedCallback(LongListSelector.OnDataTemplateChanged)));
		public static readonly DependencyProperty GroupFooterProperty = DependencyProperty.Register("GroupFooterTemplate", typeof(DataTemplate), typeof(LongListSelector), new PropertyMetadata(null, new PropertyChangedCallback(LongListSelector.OnDataTemplateChanged)));
		public static readonly DependencyProperty ItemsTemplateProperty = DependencyProperty.Register("ItemTemplate", typeof(DataTemplate), typeof(LongListSelector), new PropertyMetadata(null, new PropertyChangedCallback(LongListSelector.OnDataTemplateChanged)));
		public static readonly DependencyProperty DisplayAllGroupsProperty = DependencyProperty.Register("DisplayAllGroups", typeof(bool), typeof(LongListSelector), new PropertyMetadata(false, new PropertyChangedCallback(LongListSelector.OnDisplayAllGroupsChanged)));
		public static readonly DependencyProperty GroupItemTemplateProperty = DependencyProperty.Register("GroupItemTemplate", typeof(DataTemplate), typeof(LongListSelector), new PropertyMetadata(null));
		public static readonly DependencyProperty GroupItemsPanelProperty = DependencyProperty.Register("GroupItemsPanel", typeof(ItemsPanelTemplate), typeof(LongListSelector), new PropertyMetadata(null));
		[Obsolete("BufferSizeProperty no longer affect items virtualization")]
		public static readonly DependencyProperty BufferSizeProperty = DependencyProperty.Register("BufferSize", typeof(double), typeof(LongListSelector), new PropertyMetadata(1.0, new PropertyChangedCallback(LongListSelector.OnBufferSizeChanged)));
		[Obsolete("MaximumFlickVelocityProperty is not used anymore.")]
		public static readonly DependencyProperty MaximumFlickVelocityProperty = DependencyProperty.Register("MaximumFlickVelocity", typeof(double), typeof(LongListSelector), new PropertyMetadata(MotionParameters.MaximumSpeed));
		public static readonly DependencyProperty ShowListHeaderProperty = DependencyProperty.Register("ShowListHeader", typeof(bool), typeof(LongListSelector), new PropertyMetadata(true, new PropertyChangedCallback(LongListSelector.OnShowListHeaderChanged)));
		public static readonly DependencyProperty ShowListFooterProperty = DependencyProperty.Register("ShowListFooter", typeof(bool), typeof(LongListSelector), new PropertyMetadata(true, new PropertyChangedCallback(LongListSelector.OnShowListFooterChanged)));
		private bool mBIsGroupViewOpend;
		public event SelectionChangedEventHandler SelectionChanged;
		public event EventHandler ScrollingStarted;
		public event EventHandler ScrollingCompleted;
		public event EventHandler<GroupViewOpenedEventArgs> GroupViewOpened;
		public event EventHandler<GroupViewClosingEventArgs> GroupViewClosing;
		public event EventHandler<LinkUnlinkEventArgs> Link;
		public event EventHandler<LinkUnlinkEventArgs> Unlink;
		public event EventHandler StretchingBottom;
		public event EventHandler StretchingCompleted;
		public event EventHandler StretchingTop;
		public bool IsShowSelectorByApp
		{
			get;
			set;
		}
		public bool IsFlatList
		{
			get;
			set;
		}
		public object SelectedItem
		{
			get
			{
				if (this._listBox != null && this._listBox.get_SelectedItem() != null)
				{
					LongListSelectorItem longListSelectorItem = (LongListSelectorItem)this._listBox.get_SelectedItem();
					if (longListSelectorItem.ItemType == LongListSelectorItemType.Item)
					{
						return longListSelectorItem.Item;
					}
				}
				return null;
			}
			set
			{
				if (this._listBox != null)
				{
					if (value == null)
					{
						this._listBox.set_SelectedItem(null);
						return;
					}
					IEnumerator enumerator = this._listBox.get_ItemsSource().GetEnumerator();
					try
					{
						while (enumerator.MoveNext())
						{
							LongListSelectorItem longListSelectorItem = (LongListSelectorItem)enumerator.get_Current();
							if (longListSelectorItem.Item == value)
							{
								this._listBox.set_SelectedItem(longListSelectorItem);
								break;
							}
						}
					}
					finally
					{
						IDisposable disposable = enumerator as IDisposable;
						if (disposable != null)
						{
							disposable.Dispose();
						}
					}
				}
			}
		}
		[Obsolete("IsBouncy is always set to true.")]
		public bool IsBouncy
		{
			get
			{
				return true;
			}
			set
			{
			}
		}
		private bool HasListHeader
		{
			get
			{
				return this.ListHeaderTemplate != null || this.ListHeader is UIElement;
			}
		}
		private bool HasListFooter
		{
			get
			{
				return this.ListFooterTemplate != null || this.ListFooter is UIElement;
			}
		}
		public bool IsScrolling
		{
			get;
			private set;
		}
		public bool IsStretching
		{
			get;
			private set;
		}
		public IEnumerable ItemsSource
		{
			get
			{
				return (IEnumerable)base.GetValue(LongListSelector.ItemsSourceProperty);
			}
			set
			{
				base.SetValue(LongListSelector.ItemsSourceProperty, value);
			}
		}
		public object ListHeader
		{
			get
			{
				return base.GetValue(LongListSelector.ListHeaderProperty);
			}
			set
			{
				base.SetValue(LongListSelector.ListHeaderProperty, value);
			}
		}
		public DataTemplate ListHeaderTemplate
		{
			get
			{
				return (DataTemplate)base.GetValue(LongListSelector.ListHeaderTemplateProperty);
			}
			set
			{
				base.SetValue(LongListSelector.ListHeaderTemplateProperty, value);
			}
		}
		public object ListFooter
		{
			get
			{
				return base.GetValue(LongListSelector.ListFooterProperty);
			}
			set
			{
				base.SetValue(LongListSelector.ListFooterProperty, value);
			}
		}
		public DataTemplate ListFooterTemplate
		{
			get
			{
				return (DataTemplate)base.GetValue(LongListSelector.ListFooterTemplateProperty);
			}
			set
			{
				base.SetValue(LongListSelector.ListFooterTemplateProperty, value);
			}
		}
		public DataTemplate GroupHeaderTemplate
		{
			get
			{
				return (DataTemplate)base.GetValue(LongListSelector.GroupHeaderProperty);
			}
			set
			{
				base.SetValue(LongListSelector.GroupHeaderProperty, value);
			}
		}
		public DataTemplate GroupFooterTemplate
		{
			get
			{
				return (DataTemplate)base.GetValue(LongListSelector.GroupFooterProperty);
			}
			set
			{
				base.SetValue(LongListSelector.GroupFooterProperty, value);
			}
		}
		public DataTemplate ItemTemplate
		{
			get
			{
				return (DataTemplate)base.GetValue(LongListSelector.ItemsTemplateProperty);
			}
			set
			{
				base.SetValue(LongListSelector.ItemsTemplateProperty, value);
			}
		}
		public bool DisplayAllGroups
		{
			get
			{
				return (bool)base.GetValue(LongListSelector.DisplayAllGroupsProperty);
			}
			set
			{
				base.SetValue(LongListSelector.DisplayAllGroupsProperty, value);
			}
		}
		public DataTemplate GroupItemTemplate
		{
			get
			{
				return (DataTemplate)base.GetValue(LongListSelector.GroupItemTemplateProperty);
			}
			set
			{
				base.SetValue(LongListSelector.GroupItemTemplateProperty, value);
			}
		}
		public ItemsPanelTemplate GroupItemsPanel
		{
			get
			{
				return (ItemsPanelTemplate)base.GetValue(LongListSelector.GroupItemsPanelProperty);
			}
			set
			{
				base.SetValue(LongListSelector.GroupItemsPanelProperty, value);
			}
		}
		[Obsolete("BufferSize no longer affect items virtualization")]
		public double BufferSize
		{
			get
			{
				return (double)base.GetValue(LongListSelector.BufferSizeProperty);
			}
			set
			{
				base.SetValue(LongListSelector.BufferSizeProperty, value);
			}
		}
		[Obsolete("MaximumFlickVelocity is not used anymore.")]
		public double MaximumFlickVelocity
		{
			get
			{
				return (double)base.GetValue(LongListSelector.MaximumFlickVelocityProperty);
			}
			set
			{
				base.SetValue(LongListSelector.MaximumFlickVelocityProperty, value);
			}
		}
		public bool ShowListHeader
		{
			get
			{
				return (bool)base.GetValue(LongListSelector.ShowListHeaderProperty);
			}
			set
			{
				base.SetValue(LongListSelector.ShowListHeaderProperty, value);
			}
		}
		public bool ShowListFooter
		{
			get
			{
				return (bool)base.GetValue(LongListSelector.ShowListFooterProperty);
			}
			set
			{
				base.SetValue(LongListSelector.ShowListFooterProperty, value);
			}
		}
		private void OpenPopup()
		{
			this.SaveSystemState(false, false);
			this.BuildPopup();
			this.AttachToPageEvents();
			this._groupSelectorPopup.set_IsOpen(true);
			base.UpdateLayout();
		}
		private void popup_Opened(object sender, EventArgs e)
		{
			SafeRaise.Raise<GroupViewOpenedEventArgs>(this.GroupViewOpened, this, () => new GroupViewOpenedEventArgs(this._itemsControl));
		}
		private bool ClosePopup(object selectedGroup, bool raiseEvent)
		{
			if (raiseEvent)
			{
				GroupViewClosingEventArgs args = null;
				SafeRaise.Raise<GroupViewClosingEventArgs>(this.GroupViewClosing, this, () => args = new GroupViewClosingEventArgs(this._itemsControl, selectedGroup));
				if (args != null && args.Cancel)
				{
					return false;
				}
			}
			if (this._groupSelectorPopup != null)
			{
				this.RestoreSystemState();
				this._groupSelectorPopup.set_IsOpen(false);
				this.DetachFromPageEvents();
				this._groupSelectorPopup.set_Child(null);
				this._border = null;
				this._itemsControl = null;
				this._groupSelectorPopup = null;
			}
			return true;
		}
		private void BuildPopup()
		{
			this._groupSelectorPopup = new Popup();
			this._groupSelectorPopup.add_Opened(new EventHandler(this.popup_Opened));
			this._groupSelectorPopup.set_Margin(new Thickness(0.0, -20.0, 0.0, 0.0));
			SolidColorBrush solidColorBrush = base.get_Background() as SolidColorBrush;
			Color color = (Color)base.get_Resources().get_Item("PhoneBackgroundColor");
			if (solidColorBrush != null)
			{
				Color arg_81_0 = solidColorBrush.get_Color();
				if (solidColorBrush.get_Color().get_A() > 0)
				{
					color = solidColorBrush.get_Color();
				}
			}
			Border border = new Border();
			border.set_Background(new SolidColorBrush(Color.FromArgb(160, color.get_R(), color.get_G(), color.get_B())));
			this._border = border;
			this._border.add_ManipulationStarted(delegate(object sender, ManipulationStartedEventArgs e)
			{
				e.set_Handled(true);
			});
			this._border.add_ManipulationCompleted(delegate(object sender, ManipulationCompletedEventArgs e)
			{
				e.set_Handled(true);
			});
			this._border.add_ManipulationDelta(delegate(object sender, ManipulationDeltaEventArgs e)
			{
				e.set_Handled(true);
			});
			EventHandler<GestureEventArgs> eventHandler = delegate(object sender, GestureEventArgs e)
			{
				e.set_Handled(true);
			};
			this._border.add_Tap(eventHandler);
			this._border.add_DoubleTap(eventHandler);
			this._border.add_Hold(eventHandler);
			this._itemsControl = new LongListSelector.LongListSelectorItemsControl();
			this._itemsControl.set_ItemTemplate(this.GroupItemTemplate);
			this._itemsControl.set_ItemsPanel(this.GroupItemsPanel);
			this._itemsControl.set_ItemsSource(this.ItemsSource);
			this._itemsControl.GroupSelected += new LongListSelector.GroupSelectedEventHandler(this.itemsControl_GroupSelected);
			this._groupSelectorPopup.set_Child(this._border);
			ScrollViewer scrollViewer = new ScrollViewer();
			scrollViewer.set_HorizontalScrollBarVisibility(0);
			ScrollViewer scrollViewer2 = scrollViewer;
			this._itemsControl.set_HorizontalAlignment(1);
			this._itemsControl.set_Margin(new Thickness(0.0, 12.0, 0.0, 0.0));
			this._border.set_Child(scrollViewer2);
			scrollViewer2.set_Content(this._itemsControl);
			this.SetItemsControlSize();
		}
		private void SetItemsControlSize()
		{
			Rect transformedRect = LongListSelector.GetTransformedRect();
			if (this._border != null)
			{
				this._border.set_RenderTransform(LongListSelector.GetTransform());
				this._border.set_Width(transformedRect.get_Width());
				this._border.set_Height(transformedRect.get_Height());
			}
		}
		private void itemsControl_GroupSelected(object sender, LongListSelector.GroupSelectedEventArgs e)
		{
			if (this.ClosePopup(e.Group, true))
			{
				this.ScrollToGroup(e.Group);
			}
		}
		private void AttachToPageEvents()
		{
			PhoneApplicationFrame phoneApplicationFrame = Application.get_Current().get_RootVisual() as PhoneApplicationFrame;
			if (phoneApplicationFrame != null)
			{
				this._page = (phoneApplicationFrame.get_Content() as PhoneApplicationPage);
				if (this._page != null)
				{
					this._page.add_BackKeyPress(new EventHandler<CancelEventArgs>(this.page_BackKeyPress));
					this._page.add_OrientationChanged(new EventHandler<OrientationChangedEventArgs>(this.page_OrientationChanged));
				}
			}
		}
		private void DetachFromPageEvents()
		{
			if (this._page != null)
			{
				this._page.remove_BackKeyPress(new EventHandler<CancelEventArgs>(this.page_BackKeyPress));
				this._page.remove_OrientationChanged(new EventHandler<OrientationChangedEventArgs>(this.page_OrientationChanged));
				this._page = null;
			}
		}
		private void page_BackKeyPress(object sender, CancelEventArgs e)
		{
			e.set_Cancel(true);
			this.ClosePopup(null, true);
		}
		private void page_OrientationChanged(object sender, OrientationChangedEventArgs e)
		{
			this.SetItemsControlSize();
		}
		private static Rect GetTransformedRect()
		{
			bool flag = LongListSelector.IsLandscape(LongListSelector.GetPageOrientation());
			return new Rect(0.0, 0.0, flag ? LongListSelector._screenHeight : LongListSelector._screenWidth, flag ? LongListSelector._screenWidth : LongListSelector._screenHeight);
		}
		private static Transform GetTransform()
		{
			PageOrientation pageOrientation = LongListSelector.GetPageOrientation();
			PageOrientation pageOrientation2 = pageOrientation;
			if (pageOrientation2 == 2 || pageOrientation2 == 18)
			{
				CompositeTransform compositeTransform = new CompositeTransform();
				compositeTransform.set_Rotation(90.0);
				compositeTransform.set_TranslateX(LongListSelector._screenWidth);
				return compositeTransform;
			}
			if (pageOrientation2 != 34)
			{
				return null;
			}
			CompositeTransform compositeTransform2 = new CompositeTransform();
			compositeTransform2.set_Rotation(-90.0);
			compositeTransform2.set_TranslateY(LongListSelector._screenHeight);
			return compositeTransform2;
		}
		private static bool IsLandscape(PageOrientation orientation)
		{
			return orientation == 2 || orientation == 18 || orientation == 34;
		}
		private static PageOrientation GetPageOrientation()
		{
			PhoneApplicationFrame phoneApplicationFrame = Application.get_Current().get_RootVisual() as PhoneApplicationFrame;
			if (phoneApplicationFrame != null)
			{
				PhoneApplicationPage phoneApplicationPage = phoneApplicationFrame.get_Content() as PhoneApplicationPage;
				return phoneApplicationPage.get_Orientation();
			}
			return 0;
		}
		private void SaveSystemState(bool newSystemTrayVisible, bool newApplicationBarVisible)
		{
			PhoneApplicationFrame phoneApplicationFrame = Application.get_Current().get_RootVisual() as PhoneApplicationFrame;
			if (phoneApplicationFrame != null)
			{
				PhoneApplicationPage phoneApplicationPage = phoneApplicationFrame.get_Content() as PhoneApplicationPage;
				if (phoneApplicationPage != null && phoneApplicationPage.get_ApplicationBar() != null)
				{
					this._applicationBarVisible = phoneApplicationPage.get_ApplicationBar().get_IsVisible();
					phoneApplicationPage.get_ApplicationBar().set_IsVisible(newApplicationBarVisible);
				}
			}
		}
		private void RestoreSystemState()
		{
			PhoneApplicationFrame phoneApplicationFrame = Application.get_Current().get_RootVisual() as PhoneApplicationFrame;
			if (phoneApplicationFrame != null)
			{
				PhoneApplicationPage phoneApplicationPage = phoneApplicationFrame.get_Content() as PhoneApplicationPage;
				if (phoneApplicationPage != null && phoneApplicationPage.get_ApplicationBar() != null)
				{
					phoneApplicationPage.get_ApplicationBar().set_IsVisible(this._applicationBarVisible);
				}
			}
		}
		private static void OnItemsSourceChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
		{
			((LongListSelector)obj).OnItemsSourceChanged();
		}
		private static void OnBufferSizeChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
		{
			double num = (double)e.get_NewValue();
			if (num < 0.0)
			{
				throw new ArgumentOutOfRangeException("BufferSize");
			}
		}
		private static void OnShowListHeaderChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
		{
			LongListSelector longListSelector = (LongListSelector)obj;
			if (longListSelector._listBox != null)
			{
				Collection<LongListSelectorItem> tuples = (Collection<LongListSelectorItem>)longListSelector._listBox.get_ItemsSource();
				if (longListSelector.ShowListHeader)
				{
					longListSelector.AddListHeader(tuples);
					return;
				}
				LongListSelector.RemoveListHeader(tuples);
			}
		}
		private static void OnShowListFooterChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
		{
			LongListSelector longListSelector = (LongListSelector)obj;
			if (longListSelector._listBox != null)
			{
				Collection<LongListSelectorItem> tuples = (Collection<LongListSelectorItem>)longListSelector._listBox.get_ItemsSource();
				if (longListSelector.ShowListFooter)
				{
					longListSelector.AddListFooter(tuples);
					return;
				}
				LongListSelector.RemoveListFooter(tuples);
			}
		}
		public LongListSelector()
		{
			base.set_DefaultStyleKey(typeof(LongListSelector));
		}
		public void ScrollTo(object item)
		{
			if (this._listBox != null && item != null)
			{
				ObservableCollection<LongListSelectorItem> observableCollection = (ObservableCollection<LongListSelectorItem>)this._listBox.get_ItemsSource();
				LongListSelectorItem longListSelectorItem = observableCollection.get_Item(observableCollection.get_Count() - 1);
				this._listBox.ScrollIntoView(longListSelectorItem);
				base.UpdateLayout();
				IEnumerator enumerator = this._listBox.get_ItemsSource().GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						LongListSelectorItem longListSelectorItem2 = (LongListSelectorItem)enumerator.get_Current();
						if (longListSelectorItem2.Item != null && longListSelectorItem2.Item.Equals(item))
						{
							this._listBox.ScrollIntoView(longListSelectorItem2);
							break;
						}
					}
				}
				finally
				{
					IDisposable disposable = enumerator as IDisposable;
					if (disposable != null)
					{
						disposable.Dispose();
					}
				}
			}
		}
		public void ScrollToGroup(object group)
		{
			this.ScrollTo(group);
		}
		public void DisplayGroupView()
		{
			if (this.IsShowSelectorByApp)
			{
				if (this.GroupViewOpened != null)
				{
					this.GroupViewOpened.Invoke(this, null);
				}
				return;
			}
			if (this.mBIsGroupViewOpend)
			{
				return;
			}
			this.mBIsGroupViewOpend = true;
			if (this.GroupItemTemplate != null && !this.IsFlatList)
			{
				this.OpenPopup();
			}
		}
		public void CloseGroupView()
		{
			this.mBIsGroupViewOpend = false;
			this.ClosePopup(null, false);
		}
		[Obsolete("AnimateTo(...) call ScrollTo(...) to jump without animation to the given item.")]
		public void AnimateTo(object item)
		{
			this.ScrollTo(item);
		}
		[Obsolete("GetItemsWithContainers(...) always returns an empty collection of items. Rely on Link/Unlink to know an item get realized or unrealized.")]
		public ICollection<object> GetItemsWithContainers(bool onlyItemsInView, bool getContainers)
		{
			return new Collection<object>();
		}
		[Obsolete("GetItemsInView() always returns an empty collection of items. Rely on Link/Unlink to know an item get realized or unrealized.")]
		public ICollection<object> GetItemsInView()
		{
			return this.GetItemsWithContainers(true, false);
		}
		private void OnItemsSourceChanged()
		{
			this.LoadDataIntoListBox();
		}
		public override void OnApplyTemplate()
		{
			base.OnApplyTemplate();
			if (this._listBox != null)
			{
				this._listBox.remove_SelectionChanged(new SelectionChangedEventHandler(this.OnSelectionChanged));
				this._listBox.Link -= new EventHandler<LinkUnlinkEventArgs>(this.OnLink);
				this._listBox.Unlink -= new EventHandler<LinkUnlinkEventArgs>(this.OnUnlink);
			}
			if (this._scrollGroup != null)
			{
				this._scrollGroup.remove_CurrentStateChanging(new EventHandler<VisualStateChangedEventArgs>(this.OnScrollStateChanging));
			}
			this._listBox = ((base.GetTemplateChild("TemplatedListBox") as TemplatedListBox) ?? new TemplatedListBox());
			this._listBox.ListHeaderTemplate = this.ListHeaderTemplate;
			this._listBox.ListFooterTemplate = this.ListFooterTemplate;
			this._listBox.GroupHeaderTemplate = this.GroupHeaderTemplate;
			this._listBox.GroupFooterTemplate = this.GroupFooterTemplate;
			this._listBox.set_ItemTemplate(this.ItemTemplate);
			this._listBox.add_SelectionChanged(new SelectionChangedEventHandler(this.OnSelectionChanged));
			this._listBox.Link += new EventHandler<LinkUnlinkEventArgs>(this.OnLink);
			this._listBox.Unlink += new EventHandler<LinkUnlinkEventArgs>(this.OnUnlink);
			ScrollViewer firstLogicalChildByType = this._listBox.GetFirstLogicalChildByType(true);
			if (firstLogicalChildByType != null)
			{
				FrameworkElement frameworkElement = VisualTreeHelper.GetChild(firstLogicalChildByType, 0) as FrameworkElement;
				if (frameworkElement != null)
				{
					this._scrollGroup = VisualStates.TryGetVisualStateGroup(firstLogicalChildByType, "ScrollStates");
					if (this._scrollGroup != null)
					{
						this._scrollGroup.add_CurrentStateChanging(new EventHandler<VisualStateChangedEventArgs>(this.OnScrollStateChanging));
					}
					this._verticalCompressionGroup = VisualStates.TryGetVisualStateGroup(firstLogicalChildByType, "VerticalCompression");
					if (this._verticalCompressionGroup != null)
					{
						this._verticalCompressionGroup.add_CurrentStateChanging(new EventHandler<VisualStateChangedEventArgs>(this.OnStretchStateChanging));
					}
				}
			}
			this.LoadDataIntoListBox();
		}
		private void LoadDataIntoListBox()
		{
			if (this._listBox != null)
			{
				ObservableCollection<LongListSelectorItem> observableCollection = new ObservableCollection<LongListSelectorItem>();
				this.AddListHeader(observableCollection);
				this.UnsubscribeFromAllCollections();
				if (this.IsFlatList)
				{
					if (this.ItemsSource == null)
					{
						goto IL_CB;
					}
					IEnumerator enumerator = this.ItemsSource.GetEnumerator();
					try
					{
						while (enumerator.MoveNext())
						{
							object current = enumerator.get_Current();
							observableCollection.Add(new LongListSelectorItem
							{
								Item = current,
								ItemType = LongListSelectorItemType.Item
							});
						}
						goto IL_CB;
					}
					finally
					{
						IDisposable disposable = enumerator as IDisposable;
						if (disposable != null)
						{
							disposable.Dispose();
						}
					}
				}
				IEnumerable itemsSource = this.ItemsSource;
				if (itemsSource != null)
				{
					IEnumerator enumerator2 = itemsSource.GetEnumerator();
					try
					{
						while (enumerator2.MoveNext())
						{
							object current2 = enumerator2.get_Current();
							this.AddGroup(current2, observableCollection);
						}
					}
					finally
					{
						IDisposable disposable2 = enumerator2 as IDisposable;
						if (disposable2 != null)
						{
							disposable2.Dispose();
						}
					}
				}
				IL_CB:
				this.AddListFooter(observableCollection);
				this._rootCollection = (this.ItemsSource as INotifyCollectionChanged);
				if (this._rootCollection != null)
				{
					this._rootCollection.add_CollectionChanged(new NotifyCollectionChangedEventHandler(this.OnCollectionChanged));
				}
				this._listBox.set_ItemsSource(observableCollection);
			}
		}
		private void AddListHeader(IList<LongListSelectorItem> tuples)
		{
			if (this.HasListHeader && this.ShowListHeader && (tuples.get_Count() == 0 || tuples.get_Item(0).ItemType != LongListSelectorItemType.ListHeader))
			{
				tuples.Insert(0, new LongListSelectorItem
				{
					Item = this.ListHeader,
					ItemType = LongListSelectorItemType.ListHeader
				});
			}
		}
		private void AddListHeader()
		{
			this.AddListHeader((ObservableCollection<LongListSelectorItem>)this._listBox.get_ItemsSource());
		}
		private static void RemoveListHeader(IList<LongListSelectorItem> tuples)
		{
			if (tuples.get_Count() > 0 && tuples.get_Item(0).ItemType == LongListSelectorItemType.ListHeader)
			{
				tuples.RemoveAt(0);
			}
		}
		private void RemoveListHeader()
		{
			LongListSelector.RemoveListHeader((ObservableCollection<LongListSelectorItem>)this._listBox.get_ItemsSource());
		}
		private void AddListFooter(IList<LongListSelectorItem> tuples)
		{
			if (this.HasListFooter && this.ShowListFooter && (tuples.get_Count() == 0 || tuples.get_Item(tuples.get_Count() - 1).ItemType != LongListSelectorItemType.ListFooter))
			{
				tuples.Add(new LongListSelectorItem
				{
					Item = this.ListFooter,
					ItemType = LongListSelectorItemType.ListFooter
				});
			}
		}
		private void AddListFooter()
		{
			this.AddListFooter((ObservableCollection<LongListSelectorItem>)this._listBox.get_ItemsSource());
		}
		private static void RemoveListFooter(IList<LongListSelectorItem> tuples)
		{
			LongListSelectorItem longListSelectorItem = tuples.get_Item(tuples.get_Count() - 1);
			if (longListSelectorItem != null && longListSelectorItem.ItemType == LongListSelectorItemType.ListFooter)
			{
				tuples.RemoveAt(tuples.get_Count() - 1);
			}
		}
		private void RemoveListFooter()
		{
			LongListSelector.RemoveListFooter((ObservableCollection<LongListSelectorItem>)this._listBox.get_ItemsSource());
		}
		private void AddGroup(object groupToAdd, IList tuples)
		{
			IEnumerable enumerable = groupToAdd as IEnumerable;
			if (enumerable != null)
			{
				bool flag = false;
				if (this.GroupHeaderTemplate != null)
				{
					tuples.Add(new LongListSelectorItem
					{
						Item = enumerable,
						ItemType = LongListSelectorItemType.GroupHeader
					});
				}
				IEnumerator enumerator = enumerable.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						object current = enumerator.get_Current();
						tuples.Add(new LongListSelectorItem
						{
							Item = current,
							ItemType = LongListSelectorItemType.Item,
							Group = enumerable
						});
						flag = true;
					}
				}
				finally
				{
					IDisposable disposable = enumerator as IDisposable;
					if (disposable != null)
					{
						disposable.Dispose();
					}
				}
				if (!flag && !this.DisplayAllGroups)
				{
					if (this.GroupHeaderTemplate != null)
					{
						tuples.RemoveAt(tuples.get_Count() - 1);
					}
				}
				else
				{
					if (this.GroupFooterTemplate != null)
					{
						tuples.Add(new LongListSelectorItem
						{
							Item = enumerable,
							ItemType = LongListSelectorItemType.GroupFooter
						});
					}
				}
				INotifyCollectionChanged notifyCollectionChanged = enumerable as INotifyCollectionChanged;
				if (notifyCollectionChanged != null && !this._groupCollections.Contains(notifyCollectionChanged))
				{
					notifyCollectionChanged.add_CollectionChanged(new NotifyCollectionChangedEventHandler(this.OnCollectionChanged));
					this._groupCollections.Add(notifyCollectionChanged);
				}
			}
		}
		private void AddGroupHeadersAndFooters(bool addHeaders, bool addFooters)
		{
			int num = 0;
			if (this.HasListHeader && this.ShowListHeader)
			{
				num++;
			}
			IEnumerable itemsSource = this.ItemsSource;
			ObservableCollection<LongListSelectorItem> observableCollection = (ObservableCollection<LongListSelectorItem>)this._listBox.get_ItemsSource();
			if (itemsSource != null)
			{
				IEnumerator enumerator = itemsSource.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						object current = enumerator.get_Current();
						IEnumerable enumerable = current as IEnumerable;
						if (enumerable != null)
						{
							int headersAndItemsCountFromGroup = this.GetHeadersAndItemsCountFromGroup(enumerable);
							if (addHeaders && this.GroupHeaderTemplate != null && headersAndItemsCountFromGroup > 0)
							{
								observableCollection.Insert(num, new LongListSelectorItem
								{
									Item = current,
									ItemType = LongListSelectorItemType.GroupHeader
								});
							}
							num += headersAndItemsCountFromGroup;
							if (addFooters && this.GroupFooterTemplate != null && headersAndItemsCountFromGroup > 0)
							{
								observableCollection.Insert(num - 1, new LongListSelectorItem
								{
									Item = current,
									ItemType = LongListSelectorItemType.GroupFooter
								});
							}
						}
					}
				}
				finally
				{
					IDisposable disposable = enumerator as IDisposable;
					if (disposable != null)
					{
						disposable.Dispose();
					}
				}
			}
		}
		private void AddGroupHeaders()
		{
			this.AddGroupHeadersAndFooters(true, false);
		}
		private void AddGroupFooters()
		{
			this.AddGroupHeadersAndFooters(false, true);
		}
		private void RemoveAllGroupHeadersAndFooters(bool removeHeaders, bool removeFooters)
		{
			ObservableCollection<LongListSelectorItem> observableCollection = (ObservableCollection<LongListSelectorItem>)this._listBox.get_ItemsSource();
			for (int i = 0; i < observableCollection.get_Count(); i++)
			{
				if ((removeHeaders && observableCollection.get_Item(i).ItemType == LongListSelectorItemType.GroupHeader) || (removeFooters && observableCollection.get_Item(i).ItemType == LongListSelectorItemType.GroupFooter))
				{
					observableCollection.RemoveAt(i--);
				}
			}
		}
		private void RemoveAllGroupHeaders()
		{
			this.RemoveAllGroupHeadersAndFooters(true, false);
		}
		private void RemoveAllGroupFooters()
		{
			this.RemoveAllGroupHeadersAndFooters(false, true);
		}
		private void UnsubscribeFromAllCollections()
		{
			if (this._rootCollection != null)
			{
				this._rootCollection.remove_CollectionChanged(new NotifyCollectionChangedEventHandler(this.OnCollectionChanged));
			}
			using (List<INotifyCollectionChanged>.Enumerator enumerator = this._groupCollections.GetEnumerator())
			{
				while (enumerator.MoveNext())
				{
					INotifyCollectionChanged current = enumerator.get_Current();
					current.remove_CollectionChanged(new NotifyCollectionChangedEventHandler(this.OnCollectionChanged));
				}
			}
			this._rootCollection = null;
			this._groupCollections.Clear();
		}
		private void InsertNewGroups(IList newGroups, int newGroupsIndex)
		{
			ObservableCollection<LongListSelectorItem> observableCollection = (ObservableCollection<LongListSelectorItem>)this._listBox.get_ItemsSource();
			List<LongListSelectorItem> list = new List<LongListSelectorItem>();
			IEnumerator enumerator = newGroups.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					object current = enumerator.get_Current();
					this.AddGroup(current, list);
				}
			}
			finally
			{
				IDisposable disposable = enumerator as IDisposable;
				if (disposable != null)
				{
					disposable.Dispose();
				}
			}
			if (list.get_Count() > 0)
			{
				int groupIndexInListBox = this.GetGroupIndexInListBox(newGroupsIndex);
				using (List<LongListSelectorItem>.Enumerator enumerator2 = list.GetEnumerator())
				{
					while (enumerator2.MoveNext())
					{
						LongListSelectorItem current2 = enumerator2.get_Current();
						observableCollection.Insert(groupIndexInListBox++, current2);
					}
				}
			}
		}
		private void InsertNewItems(IList newItems, int newItemsIndex, IEnumerable group)
		{
			ObservableCollection<LongListSelectorItem> observableCollection = (ObservableCollection<LongListSelectorItem>)this._listBox.get_ItemsSource();
			List<LongListSelectorItem> list = new List<LongListSelectorItem>();
			IEnumerator enumerator = newItems.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					object current = enumerator.get_Current();
					list.Add(new LongListSelectorItem
					{
						Group = group,
						Item = current,
						ItemType = LongListSelectorItemType.Item
					});
				}
			}
			finally
			{
				IDisposable disposable = enumerator as IDisposable;
				if (disposable != null)
				{
					disposable.Dispose();
				}
			}
			if (group != null)
			{
				int num = 0;
				bool flag = ((IList)group).get_Count() == newItems.get_Count() && !this.DisplayAllGroups;
				IEnumerator enumerator2 = this.ItemsSource.GetEnumerator();
				try
				{
					while (enumerator2.MoveNext())
					{
						object current2 = enumerator2.get_Current();
						if (current2 == group)
						{
							int num2 = this.GetGroupIndexInListBox(num);
							if (this.GroupHeaderTemplate != null)
							{
								if (flag)
								{
									observableCollection.Insert(num2, new LongListSelectorItem
									{
										ItemType = LongListSelectorItemType.GroupHeader,
										Item = group
									});
								}
								num2++;
							}
							num2 += newItemsIndex;
							using (List<LongListSelectorItem>.Enumerator enumerator3 = list.GetEnumerator())
							{
								while (enumerator3.MoveNext())
								{
									LongListSelectorItem current3 = enumerator3.get_Current();
									observableCollection.Insert(num2++, current3);
								}
							}
							if (flag && this.GroupFooterTemplate != null)
							{
								observableCollection.Insert(num2++, new LongListSelectorItem
								{
									ItemType = LongListSelectorItemType.GroupFooter,
									Item = group
								});
							}
						}
						num++;
					}
					return;
				}
				finally
				{
					IDisposable disposable2 = enumerator2 as IDisposable;
					if (disposable2 != null)
					{
						disposable2.Dispose();
					}
				}
			}
			int num3 = newItemsIndex;
			if (this.HasListHeader && this.ShowListHeader)
			{
				num3++;
			}
			using (List<LongListSelectorItem>.Enumerator enumerator4 = list.GetEnumerator())
			{
				while (enumerator4.MoveNext())
				{
					LongListSelectorItem current4 = enumerator4.get_Current();
					observableCollection.Insert(num3++, current4);
				}
			}
		}
		private void RemoveOldGroups(IList oldGroups, int oldGroupsIndex)
		{
			ObservableCollection<LongListSelectorItem> observableCollection = (ObservableCollection<LongListSelectorItem>)this._listBox.get_ItemsSource();
			int num = 0;
			if (oldGroupsIndex > 0)
			{
				num = this.GetGroupIndexInListBox(oldGroupsIndex - 1);
				IEnumerable enumerable = ((IList)this.ItemsSource).get_Item(oldGroupsIndex - 1) as IEnumerable;
				if (enumerable != null)
				{
					num += this.GetHeadersAndItemsCountFromGroup(enumerable);
				}
			}
			else
			{
				if (this.HasListHeader && this.ShowListHeader)
				{
					num++;
				}
			}
			int itemsCountFromGroups = this.GetItemsCountFromGroups(oldGroups);
			for (int i = 0; i < itemsCountFromGroups; i++)
			{
				observableCollection.RemoveAt(num);
			}
			IEnumerator enumerator = oldGroups.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					INotifyCollectionChanged notifyCollectionChanged = (INotifyCollectionChanged)enumerator.get_Current();
					notifyCollectionChanged.remove_CollectionChanged(new NotifyCollectionChangedEventHandler(this.OnCollectionChanged));
				}
			}
			finally
			{
				IDisposable disposable = enumerator as IDisposable;
				if (disposable != null)
				{
					disposable.Dispose();
				}
			}
		}
		private void RemoveOldItems(IList oldItems, int oldItemsIndex, IEnumerable group)
		{
			ObservableCollection<LongListSelectorItem> observableCollection = (ObservableCollection<LongListSelectorItem>)this._listBox.get_ItemsSource();
			if (group != null)
			{
				int num = 0;
				IEnumerator enumerator = this.ItemsSource.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						object current = enumerator.get_Current();
						if (current == group)
						{
							int num2 = this.GetGroupIndexInListBox(num);
							num2 += oldItemsIndex;
							if (this.GroupHeaderTemplate != null)
							{
								num2++;
							}
							for (int i = 0; i < oldItems.get_Count(); i++)
							{
								observableCollection.RemoveAt(num2);
							}
							if (((IList)group).get_Count() == 0 && !this.DisplayAllGroups)
							{
								if (this.GroupFooterTemplate != null)
								{
									observableCollection.RemoveAt(num2);
								}
								if (this.GroupHeaderTemplate != null)
								{
									observableCollection.RemoveAt(num2 - 1);
								}
							}
						}
						num++;
					}
					return;
				}
				finally
				{
					IDisposable disposable = enumerator as IDisposable;
					if (disposable != null)
					{
						disposable.Dispose();
					}
				}
			}
			int num3 = oldItemsIndex;
			if (this.HasListHeader && this.ShowListHeader)
			{
				num3++;
			}
			for (int j = 0; j < oldItems.get_Count(); j++)
			{
				observableCollection.RemoveAt(num3);
			}
		}
		private int GetGroupIndexInListBox(int indexInLLS)
		{
			int num = 0;
			int num2 = 0;
			if (this.HasListHeader && this.ShowListHeader)
			{
				num++;
			}
			IEnumerable itemsSource = this.ItemsSource;
			if (itemsSource != null)
			{
				IEnumerator enumerator = itemsSource.GetEnumerator();
				try
				{
					while (enumerator.MoveNext())
					{
						object current = enumerator.get_Current();
						if (indexInLLS == num2)
						{
							break;
						}
						num2++;
						IEnumerable enumerable = current as IEnumerable;
						if (enumerable != null)
						{
							num += this.GetHeadersAndItemsCountFromGroup(enumerable);
						}
					}
				}
				finally
				{
					IDisposable disposable = enumerator as IDisposable;
					if (disposable != null)
					{
						disposable.Dispose();
					}
				}
			}
			return num;
		}
		private int GetItemsCountFromGroups(IEnumerable groups)
		{
			int num = 0;
			IEnumerator enumerator = groups.GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					object current = enumerator.get_Current();
					IEnumerable enumerable = current as IEnumerable;
					if (enumerable != null)
					{
						num += this.GetHeadersAndItemsCountFromGroup(enumerable);
					}
				}
			}
			finally
			{
				IDisposable disposable = enumerator as IDisposable;
				if (disposable != null)
				{
					disposable.Dispose();
				}
			}
			return num;
		}
		private int GetHeadersAndItemsCountFromGroup(IEnumerable group)
		{
			int num = 0;
			IList list = group as IList;
			if (list != null)
			{
				num += list.get_Count();
			}
			else
			{
				num += Enumerable.Count<object>(Enumerable.Cast<object>(group));
			}
			bool flag;
			if (((flag = (num > 0)) || this.DisplayAllGroups) && this.GroupHeaderTemplate != null)
			{
				num++;
			}
			if ((flag || this.DisplayAllGroups) && this.GroupFooterTemplate != null)
			{
				num++;
			}
			return num;
		}
		private void UpdateItemsTemplate(LongListSelectorItemType itemType, DataTemplate newTemplate)
		{
			if (this._listBox != null)
			{
				IEnumerable<TemplatedListBoxItem> logicalChildrenByType = this._listBox.GetLogicalChildrenByType(false);
				using (IEnumerator<TemplatedListBoxItem> enumerator = logicalChildrenByType.GetEnumerator())
				{
					while (enumerator.MoveNext())
					{
						TemplatedListBoxItem current = enumerator.get_Current();
						LongListSelectorItem tuple = current.Tuple;
						if (tuple.ItemType == itemType)
						{
							current.set_ContentTemplate(newTemplate);
						}
					}
				}
				switch (itemType)
				{
				case LongListSelectorItemType.Item:
					this._listBox.set_ItemTemplate(newTemplate);
					break;
				case LongListSelectorItemType.GroupHeader:
					this._listBox.GroupHeaderTemplate = newTemplate;
					return;
				case LongListSelectorItemType.GroupFooter:
					this._listBox.GroupFooterTemplate = newTemplate;
					return;
				case LongListSelectorItemType.ListHeader:
					this._listBox.ListHeaderTemplate = newTemplate;
					return;
				case LongListSelectorItemType.ListFooter:
					this._listBox.ListFooterTemplate = newTemplate;
					return;
				default:
					return;
				}
			}
		}
		private static void OnDataTemplateChanged(DependencyObject o, DependencyPropertyChangedEventArgs e)
		{
			LongListSelector longListSelector = (LongListSelector)o;
			if (longListSelector._listBox == null)
			{
				return;
			}
			DataTemplate newTemplate = (DataTemplate)e.get_NewValue();
			if (e.get_Property() == LongListSelector.ListHeaderTemplateProperty)
			{
				longListSelector.UpdateItemsTemplate(LongListSelectorItemType.ListHeader, newTemplate);
				if (e.get_OldValue() == null)
				{
					longListSelector.AddListHeader();
					return;
				}
				if (e.get_NewValue() == null && !longListSelector.HasListHeader)
				{
					longListSelector.RemoveListHeader();
					return;
				}
			}
			else
			{
				if (e.get_Property() == LongListSelector.ListFooterTemplateProperty)
				{
					longListSelector.UpdateItemsTemplate(LongListSelectorItemType.ListFooter, newTemplate);
					if (e.get_OldValue() == null)
					{
						longListSelector.AddListFooter();
						return;
					}
					if (e.get_NewValue() == null && !longListSelector.HasListHeader)
					{
						longListSelector.RemoveListFooter();
						return;
					}
				}
				else
				{
					if (e.get_Property() == LongListSelector.GroupHeaderProperty)
					{
						longListSelector.UpdateItemsTemplate(LongListSelectorItemType.GroupHeader, newTemplate);
						if (e.get_OldValue() == null)
						{
							longListSelector.AddGroupHeaders();
							return;
						}
						if (e.get_NewValue() == null)
						{
							longListSelector.RemoveAllGroupHeaders();
							return;
						}
					}
					else
					{
						if (e.get_Property() == LongListSelector.GroupFooterProperty)
						{
							longListSelector.UpdateItemsTemplate(LongListSelectorItemType.GroupFooter, newTemplate);
							if (e.get_OldValue() == null)
							{
								longListSelector.AddGroupFooters();
								return;
							}
							if (e.get_NewValue() == null)
							{
								longListSelector.RemoveAllGroupFooters();
								return;
							}
						}
						else
						{
							if (e.get_Property() == LongListSelector.ItemsTemplateProperty)
							{
								longListSelector.UpdateItemsTemplate(LongListSelectorItemType.Item, newTemplate);
							}
						}
					}
				}
			}
		}
		private static void OnDisplayAllGroupsChanged(DependencyObject obj, DependencyPropertyChangedEventArgs e)
		{
			((LongListSelector)obj).LoadDataIntoListBox();
		}
		private void OnSelectionChanged(object sender, SelectionChangedEventArgs e)
		{
			LongListSelectorItem longListSelectorItem = null;
			IEnumerator enumerator = e.get_AddedItems().GetEnumerator();
			try
			{
				while (enumerator.MoveNext())
				{
					LongListSelectorItem longListSelectorItem2 = (LongListSelectorItem)enumerator.get_Current();
					if (longListSelectorItem2.ItemType == LongListSelectorItemType.GroupHeader)
					{
						longListSelectorItem = longListSelectorItem2;
						break;
					}
				}
			}
			finally
			{
				IDisposable disposable = enumerator as IDisposable;
				if (disposable != null)
				{
					disposable.Dispose();
				}
			}
			if (longListSelectorItem != null)
			{
				this.SelectedItem = null;
				this.DisplayGroupView();
				return;
			}
			SelectionChangedEventHandler selectionChanged = this.SelectionChanged;
			if (selectionChanged != null)
			{
				List<LongListSelectorItem> list = new List<LongListSelectorItem>();
				List<LongListSelectorItem> list2 = new List<LongListSelectorItem>();
				IEnumerator enumerator2 = e.get_AddedItems().GetEnumerator();
				try
				{
					while (enumerator2.MoveNext())
					{
						LongListSelectorItem longListSelectorItem3 = (LongListSelectorItem)enumerator2.get_Current();
						if (longListSelectorItem3.ItemType == LongListSelectorItemType.Item)
						{
							list.Add(longListSelectorItem3);
						}
					}
				}
				finally
				{
					IDisposable disposable2 = enumerator2 as IDisposable;
					if (disposable2 != null)
					{
						disposable2.Dispose();
					}
				}
				IEnumerator enumerator3 = e.get_RemovedItems().GetEnumerator();
				try
				{
					while (enumerator3.MoveNext())
					{
						LongListSelectorItem longListSelectorItem4 = (LongListSelectorItem)enumerator3.get_Current();
						if (longListSelectorItem4.ItemType == LongListSelectorItemType.Item)
						{
							list2.Add(longListSelectorItem4);
						}
					}
				}
				finally
				{
					IDisposable disposable3 = enumerator3 as IDisposable;
					if (disposable3 != null)
					{
						disposable3.Dispose();
					}
				}
				selectionChanged.Invoke(this, new SelectionChangedEventArgs(list2, list));
			}
		}
		private void OnCollectionChanged(object sender, NotifyCollectionChangedEventArgs e)
		{
			IEnumerable group = sender as IEnumerable;
			switch (e.get_Action())
			{
			case 0:
				if (sender != this._rootCollection)
				{
					this.InsertNewItems(e.get_NewItems(), e.get_NewStartingIndex(), group);
					return;
				}
				if (this.IsFlatList)
				{
					this.InsertNewItems(e.get_NewItems(), e.get_NewStartingIndex(), null);
					return;
				}
				this.InsertNewGroups(e.get_NewItems(), e.get_NewStartingIndex());
				return;
			case 1:
				if (sender != this._rootCollection)
				{
					this.RemoveOldItems(e.get_OldItems(), e.get_OldStartingIndex(), group);
					return;
				}
				if (this.IsFlatList)
				{
					this.RemoveOldItems(e.get_OldItems(), e.get_OldStartingIndex(), null);
					return;
				}
				this.RemoveOldGroups(e.get_OldItems(), e.get_OldStartingIndex());
				return;
			case 2:
			case 4:
				this.LoadDataIntoListBox();
				break;
			case 3:
				break;
			default:
				return;
			}
		}
		private void OnScrollStateChanging(object sender, VisualStateChangedEventArgs e)
		{
			this.IsScrolling = (e.get_NewState().get_Name() == "Scrolling");
			if (e.get_NewState().get_Name() == "Scrolling" && this.ScrollingStarted != null)
			{
				this.ScrollingStarted.Invoke(this, null);
				return;
			}
			if (e.get_NewState().get_Name() == "NotScrolling" && this.ScrollingCompleted != null)
			{
				this.ScrollingCompleted.Invoke(this, null);
			}
		}
		private void OnStretchStateChanging(object sender, VisualStateChangedEventArgs e)
		{
			this.IsStretching = (e.get_NewState().get_Name() == "CompressionBottom" || e.get_NewState().get_Name() == "CompressionTop");
			if (e.get_NewState().get_Name() == "CompressionTop" && this.StretchingTop != null)
			{
				this.StretchingTop.Invoke(this, null);
				return;
			}
			if (e.get_NewState().get_Name() == "CompressionBottom" && this.StretchingBottom != null)
			{
				this.StretchingBottom.Invoke(this, null);
				return;
			}
			if (e.get_NewState().get_Name() == "NoVerticalCompression" && this.StretchingCompleted != null)
			{
				this.StretchingCompleted.Invoke(this, null);
			}
		}
		private void OnLink(object sender, LinkUnlinkEventArgs e)
		{
			if (this.Link != null)
			{
				this.Link.Invoke(this, e);
			}
		}
		private void OnUnlink(object sender, LinkUnlinkEventArgs e)
		{
			if (this.Unlink != null)
			{
				this.Unlink.Invoke(this, e);
			}
		}
	}
}
